import { messages } from "share/common";
import React, { Component } from 'react';
import { connect } from 'react-redux';
import 'styles/supplier-management/overview/consumer-other-setting.scss'
import Importer from "components/template/importer/index";
import config from "config";

class CarUseSystem extends Component {
    constructor(props) {
        super(props);
        this.state = {
            fileList: [],
            flieUploading: false,//文件是否正在上传
        }       
        //导入结果展示
        this.resultDisplay = ({ code, msg, failRegulationIds, successCount }) => {
            return <span className="didi-regulation-importer-result">
                <span className="display-block result-content">{messages('supplier-1.key25')/*导入结果：*/}{msg}</span>
                {typeof successCount === "number" && <span className="display-block success">{messages('supplier-1.key26')/*导入成功*/}{successCount}条</span>}
                {failRegulationIds instanceof Array && <span className="display-block fail">{messages('supplier-1.key27')/*导入失败*/}{failRegulationIds.length}条</span>}
                {failRegulationIds && failRegulationIds instanceof Array && failRegulationIds.length > 0 && <span className="result-block">{messages('supplier-1.key28')/*失败制度ID:*/}<br/>{failRegulationIds.join(" , ")}</span>}
            </span>
        }
    }

    resultTemplate = data => {
        const Result = this.resultDisplay;
        return <Result {...data} />

    }

    render() {
        const templates = [
            {
                downloadName: messages('supplier-1.key29')/*用车制度导入模板*/,
                templateName: messages('supplier-1.key29')/*用车制度导入模板*/,
                downloadUrl: "/didi/api/didi/regulation/export",
                downloading: "didiLoading"
            }
        ];

        return (
            <div>
                <div className='consumer-other-setting-card-container'>
                    <h3>{messages('supplier-1.key30')/*用车制度导入*/}</h3>
                    <ul>
                        <li key='other'>
                            <span>{messages('supplier-1.key31')/*滴滴用车制度导入,点击*/}</span>
                            <Importer
                                triggerNode={
                                    <a>{messages('common.import')/*导入*/}</a>
                                }
                                templateOptions={{ templateList: templates , errorParser:err => err.message}}
                                uploadOptions={{
                                    queryMode: true,
                                    uploadUrl: `${config.baseUrl}/didi/api/didi/regulation/import`,
                                    uploadParams: {
                                        flag: 0
                                    },
                                    parseUploadResult: value => value
                                }}
                                parseUploadResult={this.resultTemplate}                                
                            />
                        </li>
                    </ul>
                </div>
            </div>

        )
    }
}

function mapStateToProps(state) {
    return {}
}

export default connect(mapStateToProps)(CarUseSystem);
